var app = getApp()
var md5 = require('../../utils/md5.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    array:['男', '女'],
    index:0,
    mone:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that = this;
    var service = 'User.GetMoneyInfo'
    var user_id = wx.getStorageSync('user_id');
    var open_id = wx.getStorageSync('openid');
    var sign = md5.md5(open_id + service + user_id);
    wx.request({
      url: app.globalData.apiUrl + '?service=' + service,
      header: {
        'Content-Type': 'json'
      },
      data: {
        sign: sign,
        user_id: user_id,
        open_id: open_id
      },
      success: function (res) {
        that.setData({
          mone: res.data.data.info.moen_surplus,
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  bindPickerChange: function (e) {
    console.log(e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },
  
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  bindCancel: function () {
    wx.navigateBack({})
  },
  bindSave: function (e) {
    var that = this;
    var money = e.detail.value.amount;
    var user_name = e.detail.value.user_name;
    var user_tel = e.detail.value.user_tel;
    var user_sex = e.detail.value.user_sex;
    var user_age = e.detail.value.user_age;
    if (user_sex == 0){
      user_sex = '男';
    }else{
      user_sex = '女';
    }
    if (money == "") {
      wx.showModal({
        title: '错误',
        content: '请填写提现金额',
        showCancel: false
      })
      return
    }
    if (user_name == "") {
      wx.showModal({
        title: '错误',
        content: '请填写姓名',
        showCancel: false
      })
      return
    }
    if (user_tel == "") {
      wx.showModal({
        title: '错误',
        content: '请填写手机号',
        showCancel: false
      })
      return
    }
    if (user_age == "") {
      wx.showModal({
        title: '错误',
        content: '请填写年龄',
        showCancel: false
      })
      return
    }
    var user_id = wx.getStorageSync('user_id');
    var open_id = wx.getStorageSync('openid');
    var service = 'User.GetMoney';
    var sign = md5.md5(money + open_id + service + user_age + user_id + user_name + user_sex + user_tel);

    wx.request({
      url: app.globalData.apiUrl + '?service=' + service,
      header: {
        'Content-Type': 'json'
      },
      data: {
        sign: sign,
        user_id: user_id,
        open_id: open_id,
        money: money,
        user_name: user_name,
        user_tel: user_tel,
        user_sex: user_sex,
        user_age: user_age
      },
      success: function (res) {
        if (res.data.data.code == 0) {
          wx.showModal({
            title: '成功',
            content: '提现申请已提交，请等待审核',
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                that.bindCancel();
              }
            }
          })
        } else {
          wx.showModal({
            title: '错误',
            content: res.data.data.info,
            showCancel: false
          })
        }
      }
    })
  }
})